package com.atguigu.democustomer.service.impl;

import com.atguigu.democustomer.bean.Customer;
import com.atguigu.democustomer.mapper.CustomerMapper;
import com.atguigu.democustomer.service.CustomerService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@DS("mysql0623")
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper,Customer> implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public String getCustomerByIdWithService(String id) {
        Customer result = customerMapper.getCustomerByIdWithMapper(id);
        System.out.println(result);
        return result.toString();
    }

    @Override
    @DS("mysql0623")
    public void saveCutomerWithService(Customer customer) {
        customerMapper.insert(customer);
    }

    @Override
    public String getCustomerByNameWithService(String name) {
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);


        Customer customer = this.customerMapper.selectOne(queryWrapper);
        System.out.println(customer);
        return customer.toString();
    }

    @Override
    public Long getCount() {
        return customerMapper.getCount();
    }
}
